package cums.db.impl;

import cums.db.iface.UsersDao;
import cums.db.pers.Users;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * @time Dec 4, 2009, 1:29:09 PM
 * @author fdcube
 */
public class UsersImpl extends HibernateDaoSupport implements UsersDao {

    public Users AddorUpdateUsers(Users value) {
        this.getHibernateTemplate().saveOrUpdate(value);
        return value;
    }

    public boolean DeleteUsers(Users value) {
        try {
            this.getHibernateTemplate().delete(value);
            return true;
        } catch (DataAccessException dataAccessException) {
            logger.error(dataAccessException);
            return false;
        }
    }

    public List<Users> ListUsers(Users value) {
        return this.getHibernateTemplate().find("FROM Users ORDER BY UID");
    }

    public List<Users> FindUserByUid(int value) {
        return this.getHibernateTemplate().findByNamedParam("FROM Users AS u WHERE u.UID =:value", "value", value);
    }

    public List<Users> FindUserByName(String value) {
        return this.getHibernateTemplate().findByNamedParam("FROM Users AS u WHERE u.uname =:value", "value", value);
    }

    public List<Users> FindUser(Users value) {
        System.out.println("Here,FindUser work");
        return this.getHibernateTemplate().findByNamedParam("FROM Users AS u WHERE u.uname =:uname AND u.upwd =:upwd", new String[] { "uname", "upwd" }, new Object[] {value.getUname(),value.getUpwd()});
    }
}
